package org.wmq.housewebadmin.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.wmq.housemodel.entity.LeaseTerm;
import org.wmq.housemodel.entity.Result;
import org.wmq.housewebadmin.service.LeaseTermService;

import java.util.List;

@RestController
@RequestMapping("admin/term")
@RequiredArgsConstructor
public class LeaseTermController {
    private final LeaseTermService leaseTermService;

    @GetMapping("/list")
    public Result<List<LeaseTerm>> getLeaseTermList(){
        return Result.ok(this.leaseTermService.getList());
    }

    @PostMapping("/saveOrUpdate")
    public Result<Void> saveOrUpdateLeaseTerm(@RequestBody LeaseTerm leaseTerm){
        return this.leaseTermService.saveOrUpdate(leaseTerm);
    }

    @DeleteMapping("/{id}")
    public Result<Void> deleteLeaseTermById(@PathVariable Long id){
        if (this.leaseTermService.deleteById(id) == true){
            return Result.ok();
        }else{
            return Result.error("删除失败");
        }
    }
}
